package code;

import java.util.Scanner;

public class Analyzer {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		System.out.println();
		System.out.println("Welcome to the Elevator simulator!");
		System.out.println();
		
		double probability;
		while(true){
			System.out.print("Please enter the probability of arrival for Requests: ");
			String probabilityStr =  scanner.nextLine();
			try{
				probability = Double.parseDouble(probabilityStr);
				if(probability>=0.0 && probability<=1.0){
					break;
				}else{
					System.out.println("Probability's value should be between 0.0 and 1.0");
				}
			}catch(Exception e){
				System.out.println("Probability's value should be double!");
			}
		}
		int numOfFloors;
		while(true){
			System.out.print("Please enter the number of floors: ");
			String numOfFloorsStr = scanner.nextLine();
			try{
				numOfFloors = Integer.parseInt(numOfFloorsStr);
				if(numOfFloors>1){
					break;
				}else{
					System.out.println("Number of floors should be an integer greater than 1");
				}
			}catch(Exception e){
				System.out.println("Number of floors should be an integer");
			}
		}
		
		int numOfElevators;
		while(true){
			System.out.print("Please enter the number of elevators: ");
			String numOfElevatorsStr = scanner.nextLine();
			try{
				numOfElevators = Integer.parseInt(numOfElevatorsStr);
				if(numOfElevators>0){
					break;
				}else{
					System.out.println("Number of elevators should be an integer greater than 0");
				}
			}catch(Exception e){
				System.out.println("Number of elevators should be an integer");
			}
		}
		
		int lenghtOfSimulations;
		while(true){
			System.out.print("Please enter the length of the simulation (in time units): ");
			String lengthOfSimulationsStr = scanner.nextLine();
			try{
				lenghtOfSimulations = Integer.parseInt(lengthOfSimulationsStr);
				if(lenghtOfSimulations > 0){
					break;
				}else{
					System.out.println("Lenght of simulations should be an integer greater than 0");
				}
			}catch(Exception e){
				System.out.println("Length of simulations should be an integer");
			}
		}
		
		scanner.close();
		
		Simulator.simulate(probability, numOfFloors, numOfElevators, lenghtOfSimulations);
	}
}
